//
//  NSString+YMJDES.m
//  MD5
//
//  Created by 殷殷明静 on 16/8/16.
//  Copyright © 2016年 殷明静. All rights reserved.
//

#import "NSString+YMJDES.h"
#import <CommonCrypto/CommonCrypto.h>
// 必须8位数
#define key @"qwerasdf"
static Byte iv[] = {1,2,3,4,5,6,7,8};
@implementation NSString (YMJDES)
// 字符串对称加密(DES)
- (NSString *)stringWithDES {
    // 将字符串本身转成C字符串
    const char *string = [self UTF8String];
    size_t dataOutMoved = 0;
    // 接受容器
    unsigned char byte[1024];
    // 加密过程
    CCCryptorStatus cs = CCCrypt(kCCEncrypt,kCCAlgorithmDES, kCCOptionPKCS7Padding, [key UTF8String], kCCKeySizeDES, iv, string, strlen(string), byte, 1024, &dataOutMoved);
    if (cs == kCCSuccess) {
        // 判断是否成功
        NSData *data_ymj = [NSData dataWithBytes:byte length:dataOutMoved];
        NSString *str = [data_ymj base64EncodedStringWithOptions:0];
        return str;
    } else {
        return @"";
    }
    
        
    
}
// 字符串对称解密(DES)
- (NSString *)desWiathString {
    
    return nil;
}

@end
